package com.atguigu.gulimall.order.controller;

import com.atguigu.gulimall.order.entity.OrderEntity;
import com.atguigu.gulimall.order.entity.OrderReturnReasonEntity;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.UUID;

@RestController
public class RabbitController {
    @Autowired
    RabbitTemplate rabbitTemplate;

    @GetMapping("/rabbit")
    public String rabbit() {
        for (int i = 0; i < 10; i++) {
            if (i % 2 == 0) {
                OrderReturnReasonEntity returnApplyEntity = new OrderReturnReasonEntity();
                returnApplyEntity.setId(1L);
                returnApplyEntity.setCreateTime(new Date());
                returnApplyEntity.setName("huoHua" + i);
                String demo = "我司测试";
                //1.消息发送 是个对象 要采用序列化
                rabbitTemplate.convertAndSend("hellow-java-exchange", "hellow.java", returnApplyEntity, new CorrelationData(UUID.randomUUID().toString()));
            } else {
                OrderEntity orderEntity = new OrderEntity();
                orderEntity.setOrderSn(UUID.randomUUID().toString());
                rabbitTemplate.convertAndSend("hellow-java-exchange", "hellow", orderEntity, new CorrelationData(UUID.randomUUID().toString()));
            }
        }
        return "OK";
    }
}
